module.exports = (vm) => {
	// 初始化请求配置
	uni.$u.http.setConfig((config) => {
			config.baseURL = 'http://localhost:3000';
			return config
	})

	// 请求拦截
	uni.$u.http.interceptors.request.use((config) => { 
		config.data = config.data || {}
		config.header.Accept = "application/json";
		return config
	}, config => { 
		return Promise.reject(config)
	})

	// 响应拦截
	uni.$u.http.interceptors.response.use((response) => {
		const data = response.data
		if (response.statusCode === 200 || response.statusCode === 201) {
			//console.log("请求成功!")
			//console.log(data);
			//console.log(response.config.url);
			return response.data;
		} else {
			console.log("数据返回异常!")
			return Promise.reject("数据返回异常")
		}
		return data
	}, (response) => {
		uni.$u.toast("网络请求异常!")
		return Promise.reject(response)
	})
}
